/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */

package com.xw.app.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.xw.framework.base.dao.BaseUpdatableEntity;
import com.xw.util.ConvertUtils;

/**
 * The Class AcctRole.
 *
 * @author Xi Wei
 * @version 1.0
 * @since 1.0
 */
@Entity
@Table(name = "acct_role")
@DynamicUpdate(value=true)
@DynamicInsert(value=true)
public class AcctRole extends BaseUpdatableEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;

	


	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	private Long systemId;
	
	@NotBlank @Length(max=45)
	
	@Column(name = "role_code", unique = true, nullable = false, insertable = true, updatable = true, length = 45)
	private java.lang.String roleCode; //roleCode
	@NotBlank @Length(max=250)
	
	@Column(name = "role_name", unique = false, nullable = false, insertable = true, updatable = true, length = 250)
	private java.lang.String roleName; //roleName
	@Length(max=250)
	
	@Column(name = "role_desc", unique = false, nullable = true, insertable = true, updatable = true, length = 250)
	private java.lang.String roleDesc; //roleDesc
	
	
	/**
	 * Gets the system id.
	 *
	 * @return the system id
	 */
	//columns END
	public Long getSystemId() {
		return systemId;
	}

	/**
	 * Sets the system id.
	 *
	 * @param systemId the new system id
	 */
	public void setSystemId(Long systemId) {
		this.systemId = systemId;
	}

	/**
	 * Gets the role code.
	 *
	 * @return the role code
	 */
	public java.lang.String getRoleCode() {
		return this.roleCode;
	}
	
	/**
	 * Sets the role code.
	 *
	 * @param value the new role code
	 */
	public void setRoleCode(java.lang.String value) {
		this.roleCode = value;
	}

	/**
	 * Gets the role name.
	 *
	 * @return the role name
	 */
	public java.lang.String getRoleName() {
		return this.roleName;
	}
	
	/**
	 * Sets the role name.
	 *
	 * @param value the new role name
	 */
	public void setRoleName(java.lang.String value) {
		this.roleName = value;
	}

	/**
	 * Gets the role desc.
	 *
	 * @return the role desc
	 */
	public java.lang.String getRoleDesc() {
		return this.roleDesc;
	}
	
	/**
	 * Sets the role desc.
	 *
	 * @param value the new role desc
	 */
	public void setRoleDesc(java.lang.String value) {
		this.roleDesc = value;
	}


	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@Fetch(FetchMode.SUBSELECT)
	@Cascade(value=CascadeType.ALL)
	@JoinTable(name = "acct_role_menu", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "menu_id") })
	private List<SysMenu> menuList = Lists.newArrayList();
	
	/**
	 * Gets the menu list.
	 *
	 * @return the menu list
	 */
	public List<SysMenu> getMenuList() {
		return this.menuList;
	}

	/**
	 * Sets the menu list.
	 *
	 * @param menuList the new menu list
	 */
	public void setMenuList(List<SysMenu> menuList) {
		this.menuList = menuList;
	}
	
	
	@Transient
	private String menuNames;

	/**
	 * Gets the menu names.
	 *
	 * @return the menu names
	 */
	public String getMenuNames() {
		return ConvertUtils.convertElementPropertyToString(getMenuList(), "menuName", ",");
	}
	
	@Transient
	private String menuCodes;

	/**
	 * Gets the menu codes.
	 *
	 * @return the menu codes
	 */
	public String getMenuCodes() {
		return ConvertUtils.convertElementPropertyToString(getMenuList(), "menuCode", ",");
	}
	
	/**
	 * Adds the menu.
	 *
	 * @param menu the menu
	 */
	public void addMenu(SysMenu menu){
		menuList.add(menu);
	}

}

